/**
 * @file   AccessModifier.cpp
 * @author Djuro Drljaca (djurodrljaca@gmail.com)
 * @date   2014-05-01
 * @brief  Property value access modifier enum and it's supporting functions.
 *
 * Copyright 2014  Djuro Drljaca (djurodrljaca@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <DON/Core/Node/AccessModifier.h>

using namespace DON::Core;

bool Node::isAccessModifierValid(const AccessModifier accessModifier)
{
    bool success = false;

    if ((accessModifier >= AccessModifier_ReadOnly) &&
        (accessModifier <= AccessModifier_ReadWrite))
    {
        success = true;
    }

    return success;
}

Node::AccessModifier Node::fromBinaryToAccessModifier(const char data)
{
    AccessModifier accessModifier = AccessModifier_Invalid;

    if ((data >= static_cast<char>(AccessModifier_ReadOnly)) &&
        (data <= static_cast<char>(AccessModifier_ReadWrite)))
    {
        accessModifier = static_cast<AccessModifier>(data);
    }

    return accessModifier;
}

char Node::fromAccessModifierToBinary(const AccessModifier accessModifier, bool *ok)
{
    char value = 0;
    bool success = false;

    if (isAccessModifierValid(accessModifier))
    {
        value = static_cast<char>(accessModifier);
        success = true;
    }

    if (ok != NULL)
    {
        *ok = success;
    }

    return value;
}
